package cn.demographic.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.demographic.dao.ApplicanttableMapper;
import cn.demographic.dao.RegistryMapper;
import cn.demographic.dao.UserMapper;
import cn.demographic.entity.RegionAndNumberOfPeople;
import cn.demographic.service.FloatingPopulationService;
@Service
public class FloatingPopulationServiceImpl implements FloatingPopulationService {
	@Autowired
	private UserMapper userMapper;
	@Autowired
	private RegistryMapper registryMapper;
	@Autowired
	private ApplicanttableMapper applicanttableMapper;
	
	/**
	 * 查询图表统计
	 * @param map
	 * @return
	 */
	public List<RegionAndNumberOfPeople> selectRegionPeople(Map<String,Object> map){
		return userMapper.selectRegionPeople(map);
	};
	
	/**
	 * 查询图表统计(默认全国省份的人口数量)
	 * @param map
	 * @return
	 */
	public List<RegionAndNumberOfPeople> selectProvincePeople(Map<String,Object> map){
		Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String Time = dateFormat.format(date);
		String strtimeYear = Time.substring(0, Time.indexOf("-"));
		String strtimeMonth = Time.substring(Time.indexOf("-")+2, Time.lastIndexOf("-") );
		map.put("Time", strtimeYear);
		map.put("month", strtimeMonth);
		return userMapper.selectProvincePeople(map);
	};
	
	/**
	 * 	本月录入数量
	 * @param map
	 * @return
	 */
	public Long selectCountPeople(Map<String,Object> map){
		Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String Time = dateFormat.format(date);
		String strtimeYear = Time.substring(0, Time.indexOf("-"));
		String strtimeMonth = Time.substring(Time.indexOf("-")+2, Time.lastIndexOf("-") );
		map.put("Time", strtimeYear);
		map.put("month", strtimeMonth);
		return userMapper.selectCountPeople(map);
	};
	
	/**
	 * 查询本月注册用户的量
	 * @param map
	 * @return
	 */
	public Long selectCountRegistry(Map<String,Object> map){
		Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String Time = dateFormat.format(date);
		String strtimeYear = Time.substring(0, Time.indexOf("-"));
		String strtimeMonth = Time.substring(Time.indexOf("-")+2, Time.lastIndexOf("-") );
		map.put("Time", strtimeYear);
		map.put("month", strtimeMonth);
		return registryMapper.selectCountRegistry(map);
	};
	
	/**
     * 查询待审核数量
     * @param map
     * @return
     */
    public Long selectCountApplicanttable(Map<String,Object> map) {
    	Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String Time = dateFormat.format(date);
		String strtimeYear = Time.substring(0, Time.indexOf("-"));
		String strtimeMonth = Time.substring(Time.indexOf("-")+2, Time.lastIndexOf("-") );
		map.put("Time", strtimeYear);
		map.put("month", strtimeMonth);
		return applicanttableMapper.selectCountApplicanttable(map);
    };
	
    /**
     * 查询审核未通过数量
     * @param map
     * @return
     */
    public Long selectCountNotApplicanttable(Map<String,Object> map) {
    	Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String Time = dateFormat.format(date);
		String strtimeYear = Time.substring(0, Time.indexOf("-"));
		String strtimeMonth = Time.substring(Time.indexOf("-")+2, Time.lastIndexOf("-") );
		map.put("Time", strtimeYear);
		map.put("month", strtimeMonth);
		return applicanttableMapper.selectCountNotApplicanttable(map);
    };
    
    
    /**
	 * 根据手机号查询数据库，是否已经存在该手机号
	 * @param mobilePhone
	 * @return
	 */
	public Integer selectCountMobilePhone(String mobilePhone) {
		return userMapper.selectCountMobilePhone(mobilePhone);
	};
	
	/**
	 * 根据身份证查询是否存在该身份证号码
	 * @param citizenshipNumber
	 * @return
	 */
	public Integer selectCountCitizenshipNumber(String citizenshipNumber) {
		return userMapper.selectCountCitizenshipNumber(citizenshipNumber);
	};

}
